package com.lk.api.app;

import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.util.Log;
import android.widget.Toast;

import com.lk.api.R;

/**
 * Created by lk on 2014/12/22.
 */
public class MyPreferenceScreen extends PreferenceFragment {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.settings);
        Log.d("PreferenceFragment", "onCreate");
        Preference pref = findPreference("WIFI");
        pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                String key = preference.getKey();
                Toast.makeText(getActivity(), preference.getTitle()+" "+key, Toast.LENGTH_LONG).show();
//返回false 表示拦截值并且不保存 返回true 表示不拦截值自动保存
                return false;
            }
        });


    }


    @Override
    public void onStart() {
        Log.d("PreferenceFragment", "onStart");
        super.onStart();
    }


    @Override
    public void onResume() {
        Log.d("PreferenceFragment", "onResume");

        super.onResume();
    }

    @Override
    public void onPause() {
        Log.d("PreferenceFragment", "onPause");
        super.onPause();
    }

    @Override
    public void onStop() {
        Log.d("PreferenceFragment", "onStop");
        super.onStop();
    }

    @Override
    public void onDestroy() {
        Log.d("PreferenceFragment", "onDestroy");
        System.exit(0);
        super.onDestroy();
    }

}
